/*    */ package com.wzh.service.bookinfo.booktype;
/*    */ 
/*    */ import com.wzh.bean.book.BookType;
/*    */ import com.wzh.service.base.DaoSupport;
/*    */ import com.wzh.utils.PropertiesUtil;
/*    */ import java.util.ArrayList;
/*    */ import java.util.Iterator;
/*    */ import java.util.List;
/*    */ import javax.persistence.EntityManager;
/*    */ import javax.persistence.Query;
/*    */ import org.springframework.stereotype.Service;
/*    */ import org.springframework.transaction.annotation.Transactional;
/*    */ 
/*    */ @Service
/*    */ @Transactional
/*    */ public class BookTypeServiceBean extends DaoSupport<BookType>
/*    */   implements BookTypeService
/*    */ {
/*    */   public void addBookTypes(List<BookType> booktypes)
/*    */   {
/* 21 */     if (booktypes != null)
/* 22 */       for (BookType booktype : booktypes)
/* 23 */         super.save(booktype);
/*    */   }
/*    */ 
/*    */   public BookType findTypeByFilename(String filename)
/*    */   {
/* 32 */     Query query = this.em.createQuery("select o from BookType o where o.filename=?1");
/* 33 */     query.setParameter(1, filename);
/* 34 */     query.setMaxResults(1);
/*    */ 
/* 36 */     List list = query.getResultList();
/* 37 */     if ((list != null) && (list.size() > 0)) {
/* 38 */       return (BookType)list.get(0);
/*    */     }
/* 40 */     return null;
/*    */   }
/*    */ 
/*    */   public List<BookType> getMenus(int num)
/*    */   {
/* 46 */     Query query = this.em.createNativeQuery("select id, name, filename from booktype o limit ?1");
/* 47 */     query.setParameter(1, Integer.valueOf(num));
/*    */ 
/* 49 */     List list = query.getResultList();
/* 50 */     List booktypes = new ArrayList();
/* 51 */     for (Iterator localIterator = list.iterator(); localIterator.hasNext(); ) { Object obj = localIterator.next();
/* 52 */       Object[] objs = (Object[])obj;
/* 53 */       BookType bookType = new BookType();
/* 54 */       bookType.setId((Integer)objs[0]);
/* 55 */       bookType.setName((String)objs[1]);
/* 56 */       bookType.setFilename((String)objs[2]);
/*    */ 
/* 58 */       setReadurl(bookType);
/*    */ 
/* 61 */       booktypes.add(bookType);
/*    */     }
/* 63 */     return booktypes;
/*    */   }
/*    */ 
/*    */   public void setReadurl(BookType bookType)
/*    */   {
/* 69 */     PropertiesUtil properUtil = new PropertiesUtil("config.properties");
/* 70 */     if ("0".equals(properUtil.getProperty("urlwrite_tag")))
/*    */     {
/* 72 */       bookType.setListurl("/home/list?type=" + bookType.getId());
/*    */     }
/*    */     else
/*    */     {
/*    */       String urlStr;
/* 76 */       if ("1".equals(properUtil.getProperty("url_mode")))
/*    */       {
/* 78 */         urlStr = "/list/" + bookType.getId() + "/";
/*    */       }
/* 80 */       else urlStr = "/" + bookType.getFilename() + "/";
/*    */ 
/* 82 */       bookType.setListurl(urlStr);
/*    */     }
/*    */   }
/*    */ }

/* Location:           C:\work\apache-tomcat-7.0.55\webapps\ROOT\WEB-INF\classes\
 * Qualified Name:     com.wzh.service.bookinfo.booktype.BookTypeServiceBean
 * JD-Core Version:    0.6.1
 */